/*
action creator:
专门用于创建action对象
 */

import {DECREMENT, INCREMENT} from "../constants";

const waitTest = (wait) => {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('hahah')
    }, wait)
  })
}

export const increment = (data) => ({type: INCREMENT, data})
export const decrement = (data) => ({type: DECREMENT, data})

// 异步action，返回的是一个函数
export const incrementAsync = (data, wait) => {

  /*return dispatch => {
    setTimeout(()=>{
      dispatch(createIncrementAction(data))
    },wait)
  }*/
  return async (dispatch) => {
    await waitTest(wait);
    dispatch(increment(data))
  }
}
